package mylab.main;

import java.io.IOException;
import java.math.BigDecimal;

import mylab.commons.pool.EmployeeFactory;
import mylab.object.Person;

import org.apache.commons.pool.impl.GenericObjectPool;

public class Main {
	

	public static void changeName(Person p, int n)
	{
		//p.setName("new"+p.getName());
		Person np = new Person("np", 34);
		p=np;
		n=9;
	}
	
	public static void testParaPass()
	{
		int testnum =0;
		Person p = new Person("Peng",23);
		System.out.println(p.getName());
		changeName(p, testnum);
		System.out.println(p.getName() + " tesnum="+testnum);
	}
	public static void testPool() throws Exception
	{
		GenericObjectPool pool = new GenericObjectPool(new EmployeeFactory());
	    pool.setMaxActive(2);
		//pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK );
		//pool.setMaxWait(-1);
	    //pool.setFactory(new EmployeeFactory());

	    System.err.println("Number of employees in pool: " + pool.getNumIdle());
	    System.err.println("Number of Active employees from pool: " + pool.getNumActive());

	    for(int i = 0; i < 2; ++i) {
	      pool.addObject();
	    }
	    System.err.println("Number of employees in pool: " + pool.getNumIdle());
	    System.err.println("Number of Active employees from pool: " + pool.getNumActive());
	    
	    
	    TestObjectPool testObj = new TestObjectPool(pool);
	    testObj.start();
	    
	    TestObjectPool testObj2 = new TestObjectPool(pool);
	    testObj2.start();
	    
	    TestObjectPool testObj3 = new TestObjectPool(pool);
	    testObj3.start();
	    
	    TestObjectPool testObj4 = new TestObjectPool(pool);
	    testObj4.start();
	}
	public static void main(String args[]) throws Exception
	{
		
		testParaPass();
		//testPool();
		


	}
	
	

}
